package com.LostAndFound.web.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.LostAndFound.domain.SystemInfo;
import com.LostAndFound.service.WelcomeService;
import com.google.gson.Gson;

public class WelcomeServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	WelcomeService service = new WelcomeService();
	
	//在welcome.jsp中显示前8条最新的系统信息
	public void showSystemInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<Map<String, Object>> mapList = service.showSystemInfo();
		/*for(int i=0;i<mapList.size();i++) {
			System.out.println(mapList.get(i));
		}*/
		Gson gson = new Gson();
		String json = gson.toJson(mapList);
		response.setCharacterEncoding("UTF-8");
		response.getWriter().write(json);
	}
	// 展示记录的详细信息
	public void showInfoDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String infoid = request.getParameter("infoid");
		SystemInfo systemInfo = null;
		systemInfo = service.showInfoDetail(infoid);
		Gson gson = new Gson();
		String json = gson.toJson(systemInfo);
		response.setCharacterEncoding("UTF-8");
		response.getWriter().write(json);
	}
	// 获取预约领取失物记录数
	public void getTotalSearchToShow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int totalLose = 0, totalLoser = 0;
		totalLose = service.getTotalSearchLoseToShow();
		totalLoser = service.getTotalSearchLoserToShow();
		// {"totalLose":totalLose,"totalLoser":totalLoser}
		// response.getWriter().write("{\"totalLose\":"+totalLose+"}");
		response.getWriter().write("{\"totalLose\":"+totalLose+",\"totalLoser\":"+totalLoser+"}");
	}
	
}